<?php
session_start();
//require_once("../config/include.inc.php");
require_once("../config/include_tokyo.inc.php");
require_once("../class/Common_Function.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1 || $userRole == 4 || $userRole == 5 || $userRole == 8){
	//管理员,订单管理员,任务管理员+订单管理员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}


//操作
$doFlag = $_POST["doFlag"];
if($doFlag == "doSave"){
	//订单状态修改
	$orderId = $_POST["orderId"];
	$sql = "update orders set order_status = 30 where id=".$orderId;//订单状态:已发货
	$db->Execute($sql);
	$processStr = "已发货,等快递单";
	$sql = "insert into orderprocess(order_id,order_process) values ($orderId,'$processStr')";
	$db->Execute($sql);	
	//插入快递单	
	$sql = "SELECT * from orders where id=".$orderId;
	$result = $db->Execute($sql);
	if(!$result->EOF){
		$order_site = $result->fields['order_site'];
		$order_no = $result->fields['order_no'];
		$battery_flag = $result->fields['battery_flag'];
		$customer_name = $result->fields['customer_name'];
		$customer_telephone = $result->fields['customer_telephone'];
		$customer_address = $result->fields['customer_address'];
		$customer_postcode = $result->fields['customer_postcode'];
		$customer_note = $_POST["customer_note"];
		$customer_email = $result->fields['customer_email'];
		$product_description = $_POST["product_description"];
		$sql = "insert into trackingnumber
		(order_site,order_no,battery_flag,create_time,customer_name,customer_telephone,customer_address,customer_postcode,customer_note,customer_email,product_description) values 
		('$order_site','$order_no',$battery_flag,now(),'$customer_name','$customer_telephone','$customer_address','$customer_postcode','$customer_note','$customer_email','$product_description')";
		
		$db->Execute($sql);	
	}
}



//快递单详情 
$id = $_GET['id'];
$sql = "SELECT * from orders where id=".$id;
$result = $db->Execute($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "快递单详情"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>



<form name="inputForm" action="../order/sendPackage.php" method="post">
<div id="container" >	
<div class="grayTable">	
<h4>快递单详情:
</h4>

<table >
<thead>
	<tr>
		<th scope="col" width=70>字段名称</th>
	    <th scope="col" >字段值</th>		
	</tr>
</thead>

<?php
if(!$result->EOF){
	$commonFunction = new Common_Function();
	$strTR = "";
	$strTR = $strTR."<tr ><td>网站名称</td>";
	$strTR = $strTR."<td>".$result->fields['order_site']."</td></tr>";	
	$strTR = $strTR."<tr ><td>订单编号</td>";
	$strTR = $strTR."<td>".$result->fields['order_no']."</td></tr>";
	$strTR = $strTR."<tr ><td>电池状态</td>";
	$strTR = $strTR."<td>".$commonFunction->getBatteryStatusName($result->fields['battery_flag'])."</td></tr>";
	$strTR = $strTR."<tr ><td>客户名字</td>";
	$strTR = $strTR."<td>".$result->fields['customer_name']."</td></tr>";
	$strTR = $strTR."<tr ><td>客户电话</td>";
	$strTR = $strTR."<td>".$result->fields['customer_telephone']."</td></tr>";
	$strTR = $strTR."<tr ><td>客户地址</td>";
	$strTR = $strTR."<td>".$result->fields['customer_address']."</td></tr>";
	$strTR = $strTR."<tr ><td>客户邮编</td>";
	$strTR = $strTR."<td>".$result->fields['customer_postcode']."</td></tr>";
	$strTR = $strTR."<tr ><td>客户备注</td>";
	$strTR = $strTR."<td><input type='text' name='customer_note' id='customer_note' size=64></td></tr>";
	$strTR = $strTR."<tr ><td>客户Email</td>";
	$strTR = $strTR."<td>".$result->fields['customer_email']."</td></tr>";
	$strTR = $strTR."<tr ><td>产品描述</td>";
	$strTR = $strTR."<td><input type='text' name='product_description' id='product_description' size=64 value='sample laser flashlight'></td></tr>";
	echo $strTR;
}
?>
<tr><td colspan=2 align=center>
<input type="button" value="确定" onclick="doSave()">
<input type="button" value="关闭" onClick="doClose()">
</td></tr>
</table>



</div>

<br><br>

</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" >
<input type="hidden" name="orderId" id="orderId"  value="<?php echo $id; ?>">
</form>
</body>




</html>

<script>

<?php
if($doFlag == "doSave"){
	echo "doClose();";
}
?>


function doClose(){
	var isIE = navigator.appName == "Microsoft Internet Explorer";
    if(isIE){
		window.opener = "";
        window.open("","_self");
        window.close();
    }else{
		/*FF 还要在 about:config 允许脚本脚本关闭窗口*/
	    window.close();
    }
}

function doSave(){
	document.getElementById('doFlag').value = "doSave";	
	document.inputForm.submit();
}
</script>

